//app.js
const openIdUrl = "https://wx.ooooooooooo.cn/afxcx/xcx/onLogin/index.php";
App({
  onLaunch: function () {
    var that = this
    wx.request({
      url: "https://wx.ooooooooooo.cn/afxcx/xcx/contact.php",
      success: function (res) {
        console.log('拉取联系信息成功', res)
        that.globalData.phoneNumber = res.data.phoneNumber
        that.globalData.me = res.data.me
        that.globalData.address = res.data.address
        that.globalData.email = res.data.email
      },
      fail: function (res) {
        console.log('拉取联系信息失败', res)
      }
    })
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        //var that = this
        wx.request({
          url: openIdUrl,
          data: { code: res.code },
          success: function (res) {
            console.log('拉取openid成功', res)
            that.globalData.openid = res.data.openid
          },
          fail: function (res) {
            console.log('拉取用户openid失败，将无法正常使用开放接口等服务', res)
          }
        })
      }
    })
  },
  globalData: {
    phoneNumber: '',
    me: '',
    address: '',
    email: '',
    openid: ''
  }
})